home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 1997
/
MacHack 1997.toast
/
Hacks
/
Hacks ’96
/
Audio dcmds
/
Audio CD dcmds.sit
/
Audio CD dcmds.π
/
play dcmd
/
dcmd.c
< prev
next >
Wrap
Text File
|
1995-07-06
|
7KB
|
339 lines
/*****************************************************
bin.c P. Stadelmann, June 1994
Displays a long word in binary.
*****************************************************/
#include <SetUpA4.h> //dcmd.h
#include <Think_dcmd.h>
#include <Think_put.h>
#include "cd.h"
#include "toolutils.h"
#define min(x,y) (x < y ? x : y )
#define max(x,y) (x > y ? x : y )
void PlayTrack(Byte startTrack);
pascal Boolean BitTest(const void * data, long bitNum);
void DoAudioCommand(short command);
void DoHelp( void )
{
PutPStr( "\pplay [Track # | P | E | S | ? | + | - ]");
PutLine();
PutPStr( "\p Starts playing an audio CD. ");
PutLine();
PutPStr( "\p Track # - Start playing from the provided track number");
PutLine();
PutPStr( "\p P - Pause or resume play");
PutLine();
PutPStr( "\p E - Eject the disk");
PutLine();
PutPStr( "\p S - Stop playing");
PutLine();
PutPStr( "\p ? - Show current track and time info");
PutLine();
PutPStr( "\p + - Skip to the next track");
PutLine();
PutPStr( "\p - - Skip to the previous track");
PutLine();
}
void DoJob()
{
long value;
Boolean ok;
Str255 myStr;
short pos;
switch(dcmdPeekAtNextChar()) {
case '\r':
PlayTrack(1);
break;
case 'P':
case 'E':
case 'S':
case 'p':
case 'e':
case 's':
case '?':
case '+':
case '-':
pos = dcmdGetPosition();
dcmdGetNextExpression( &value, &ok );
DoAudioCommand(dcmdPeekAtNextChar());
break;
case 'V':
case 'v':
dcmdGetNextParameter(myStr);
pos = dcmdGetPosition();
dcmdSetPosition(pos);
dcmdGetNextExpression( &value, &ok );
if(ok && value >= 0 && value <= 255) {
OSErr osErr;
short ioRefNum;
osErr = OpenCD(1, &ioRefNum);
if(osErr != noErr) {
PutLine();
PutPStr( "\pCouldn't open CD Drive!");
return;
}
if(!DiscInDrive(ioRefNum)) {
PutLine();
PutPStr( "\pNo disk in CD Drive!");
return;
}
PutPStr( "\pSetting volume to ");
PutSDec(value);
ASetVolume(ioRefNum, value);
}
else {
PutPStr( "\pVolume not found or out of range");
}
break;
default:
{
pos = dcmdGetPosition();
dcmdGetNextExpression( &value, &ok );
if (ok)
{
PutPStr( "\pstarting at track ");
PutSDec(value);
PutPStr("\p…");
PlayTrack(value);
}
else
PutPStr( "\pSyntax error");
}
break;
}
PutLine();
}
void SetVolume(short value)
{
}
void DoAudioCommand(short command)
{
OSErr osErr;
short drive,
ioRefNum,
count,
track,
state;
Byte userCDNumber,
userStart,
userStop,
discStart,
discStop,
audioStatus,
playMode,
cntlField,
minutes,
seconds,
frames;
Byte trackMin, trackSec, trackFrame;
Byte currentTrack, discMin, discSec, discFrame;
userCDNumber = 1;
userStart = 0;
userStop = 100;
playMode = STEREO;
osErr = OpenCD(userCDNumber, &ioRefNum);
if(osErr != noErr) {
PutLine();
PutPStr( "\pCouldn't open CD Drive!");
return;
}
if(!DiscInDrive(ioRefNum)) {
PutLine();
PutPStr( "\pNo disk in CD Drive!");
return;
}
osErr = AStatus(ioRefNum, &audioStatus, &playMode, &cntlField, &minutes, &seconds, &frames);
discStart = 0;
do
osErr = TrackInfo(ioRefNum, ++discStart, &cntlField, &minutes, &seconds, &frames);
while (BitTst(&cntlField, 5) && noErr == osErr);
osErr = TrackCount(ioRefNum, &discStop);
osErr = ACurrTrackInfo(ioRefNum, ¤tTrack, &trackMin, &trackSec, &trackFrame);
switch (command) {
case 'p':
case 'P':
if(audioStatus == PAUSED) {
PutPStr( "\pResuming");
osErr = APause(ioRefNum, CONTINUE);
} else {
if(audioStatus == PLAYING) {
PutPStr( "\pPausing");
osErr = APause(ioRefNum, PAUSE);
}
}
break;
case 'S':
case 's':
PutPStr( "\pStopping");
osErr = AStop(ioRefNum, 0);
break;
case '+':
osErr = ATrkSearch( ioRefNum, ++currentTrack, audioStatus, playMode);
PutPStr( "\pswitching to track ");
PutSDec(currentTrack);
osErr = APause(ioRefNum, audioStatus);
break;
case '-':
if((trackMin == 0) && (trackSec <=10)) {
osErr = ATrkSearch( ioRefNum, --currentTrack, audioStatus, playMode);
}
else {
osErr = ATrkSearch( ioRefNum, currentTrack, audioStatus, playMode);
}
PutPStr( "\pswitching to track ");
PutSDec(currentTrack);
osErr = APause(ioRefNum, audioStatus);
break;
case '?':
PutPStr( "\pTrack ");
PutSDec(currentTrack);
PutPStr( "\p ");
PutSDec(trackMin);
PutPStr( "\p:");
PutSDec(trackSec);
break;
case 'E':
case 'e':
PutPStr( "\pEjecting disk");
osErr = EjectCD(ioRefNum);
break;
}
}
void PlayTrack(Byte startTrack)
{
OSErr osErr;
short drive,
ioRefNum,
count,
track,
state;
Byte userCDNumber,
userStart,
userStop,
discStart,
discStop,
audioStatus,
playMode,
cntlField,
minutes,
seconds,
frames;
userCDNumber = 1;
userStart = 0;
userStop = 100;
playMode = STEREO;
osErr = OpenCD(userCDNumber, &ioRefNum);
if(osErr != noErr) {
PutLine();
PutPStr( "\pCouldn't open CD Drive!");
return;
}
if(!DiscInDrive(ioRefNum)) {
PutLine();
PutPStr( "\pNo disk in CD Drive!");
return;
}
osErr = AStatus(ioRefNum, &audioStatus, &playMode, &cntlField, &minutes, &seconds, &frames);
if(audioStatus == PAUSED) {
osErr = APause(ioRefNum, CONTINUE);
} else {
discStart = 0;
do
osErr = TrackInfo(ioRefNum, ++discStart, &cntlField, &minutes, &seconds, &frames);
while (BitTst(&cntlField, 5) && noErr == osErr);
osErr = TrackCount(ioRefNum, &discStop);
if (noErr == osErr) {
if (startTrack == 0) {
osErr = AStop(ioRefNum, 0);
}
else {
osErr = AStop(ioRefNum, max(min(userStop, discStop), discStart));
if(startTrack > 0) {
userStart = startTrack;
osErr = APlay(ioRefNum, startTrack, playMode);
}
else{
osErr = APlay(ioRefNum, min(max(userStart, discStart), discStop), playMode);
}
}
}
}
if(osErr) {
PutPStr( "\pGot error trying to play ");
PutSDec(osErr);
}
}
//
/*
pascal Boolean BitTest(const void * data, long bitNum)
{
unsigned long mask;
unsigned long value;
if(bitNum > 31) return false;
bitNum = 31 - bitNum;
value = *((unsigned long *)data);
mask = 1 << bitNum;
return ((value & mask) != 0);
}
*/
pascal void CommandEntry( dcmdBlock* paramPtr )
{
RememberA0();
SetUpA4();
switch ( paramPtr->request )
{
case dcmdInit : break;
case dcmdHelp : DoHelp();
break;
case dcmdDoIt : DoJob();
break;
}
RestoreA4();
}